package com.lqb.webScaffold.utils;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class HutoolRSA {

    /**
     * 私钥解密
     *
     * @param content 加密了的内容
     * @throws IOException
     */
    public String decrypt(String content) throws IOException {
        String str = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAp3hVxPn9bRAeeLhG1gLqJoZgMezYGe3MA3icbkwtR8ynnEdRk5RBWnxdPmlibnDURyrbueJQA6fiiXpgl9nmWwIDAQABAkB2Gm0STuKkaXuz0vFRuBh9NsLcMpVsI8F+qS5Ysqw0N0HY0WVet2dp8NWoEyTHhIN1m9lmXDZi4Sys8u2PIIQxAiEA03idUVpTiLAUAjlpU6Wl9RiimKqLeYceA0MAeh7RjOUCIQDKu9WzyQdvxsbf7XSGxAtAWHz9d5iGnp3holvX0P2yPwIgLfLnO+YEgI7ByjnvSN2VUcwoiEOGSsGxI8RLNj28CoECICoLus6GqtwrxaM7hCdPEWZO8909qIyC6QuauKGR3ovRAiBmC6qqrgE2i7sQq3MiwyiVoKevSHtNCJMdCF7q+fGs3Q==";
        RSA rsa = new RSA(str, null);
        String result = rsa.decryptStr(content, KeyType.PrivateKey);
        return result;
    }

    /**
     * 公钥加密
     *
     * @return
     * @throws IOException
     */
    public String encrypt(String content) throws IOException {
        String str = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKd4VcT5/W0QHni4RtYC6iaGYDHs2BntzAN4nG5MLUfMp5xHUZOUQVp8XT5pYm5w1Ecq27niUAOn4ol6YJfZ5lsCAwEAAQ==";
        RSA rsa = new RSA(null, str);
        String result = rsa.encryptBase64(content, KeyType.PublicKey);
        return result;
    }
}
